package com.wang.music.controller;


import com.wang.music.entity.Song;
import com.wang.music.service.SongService;
import com.wang.music.vo.PageVO;
import com.wang.music.vo.SongVO_2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 歌曲表 前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-03-05
 */
@RestController
@RequestMapping("/song")
public class SongController {

    @Autowired
    private SongService songService;

    @PostMapping("/getSongs")
    public Map<String,Object> getSongs(String key,@RequestBody PageVO pageVO){

        return songService.getSongs(key,pageVO);
    }

    /**
     * 返回一个歌手-歌手id对应的列表
     */
    @PostMapping("/getSongList")
    public Map<String,Object> getSongList(){
        return songService.getSongList();
    }

    /**
     * 新增一个歌曲
     */
    @PostMapping("/addSong")
    public Map<String,Object> addSong(@RequestBody Song song){
        return songService.addSong(song);
    }

    /**
     * 更新歌曲
     */
    @PostMapping("/updateSong")
    public Map<String,Object> updateSong(@RequestBody Song song){
        return songService.updateSong(song);
    }

    /**
     * 删除歌曲
     */
    @PostMapping("/delSong")
    public Map<String,Object> delSong(@RequestBody Song song){
        return songService.delSong(song);
    }

    /**
     * 文件相关
     */
    @PostMapping("/uploadPic")
    public Map<String,Object> uploadPic(@RequestParam("file") MultipartFile pic){
        return songService.uploadPic(pic);
    }

    /**
     * 上传歌曲到后台，并进行处理
     * @param song
     * @return
     */
    @PostMapping("/uploadSong")
    public Map<String,Object> uploadSong(@RequestParam("file") MultipartFile song){
        return songService.uploadSong(song);
    }

    /**
     * 上传歌曲地址 用Minio的方式试试
     */
    @PostMapping("/uploadSongMinio")
    public Map<String,Object> uploadSongMinio(@RequestParam("file") MultipartFile song){
        return songService.uploadSongMinio(song);
    }

    /**
     * 根据关键字模糊查询
     */
    @GetMapping("/likeSongOfName")
    public List<SongVO_2> likeSongOfName(String songName){
        return songService.likeSongOfName(songName);
    }

}

